'-------------------
'Josh Haywood I'll Do It Myself XYZ Probe Macro
'To probe X-
'https://www.youtube.com/illdoitmyself
'Note: This script is designed for metric units e.g. mm
'-------------------
Dim ProbeDiameter As Double, FeedCurrent, XPlateWidth As Double, XPosCurrent As Double, XZeroOffset As Double

XPlateWidth = getoemdro(1153) 'Accurately measuerd plate wall width on X Axis
ProbeDiameter = GetOemDro(1000) 'Get Probe diameter
FeedCurrent = GetOemDRO(818) 'Get the current settings

If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
  Code "(Probe plate is grounded, check connection and try again)"
Else
  XPosCurrent = GetDro(0) 'Get current position
  Code "F100" 'slow feed rate to 100 mm/min

  Code "G31 X" & (PosCurrent + 25) 'probe 25mm to the left
  While GetOemLed (825) = 0
    Sleep(1)
  Wend

  Sleep(250) 'Wait for DRO to update

  XZeroOffset = ((1 * XPlateWidth) + (ProbeDiameter / 2)) 'Calculate X Zero
  Call SetDro (0, XZeroOffset) 'Set the Dro

  Sleep(250) 'Wait for DRO to update

  Code "G0 X" & (GetDro(0) + Abs(10)) & " F400" 'Move off the plate 10mm
  While IsMoving()
  Wend

  Code "(X Axis Zeroed for Platewall:" & XPlateWidth & " Tool Diameter:" & ProbeDiameter & ")"
  Code "F" & FeedCurrent 'Restore Feedrate
End If
  
